import com.aliyun.odps.udf.UDF;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

public class MomIngredientPlayTag extends UDF {
    public static void main(String[] args) {
        MomIngredientPlayTag momIngredientPlayTag = new MomIngredientPlayTag();
        String evaluate = momIngredientPlayTag.evaluate("7,6,10,3,10005107,16,111,8613,4360,44669,10323740,10323740,23,287,163,559,2058,20744,17277");
        System.out.println(evaluate);
    }

    public String evaluate(String ingredient){
        StringBuffer sbTag = new StringBuffer();
        if(StringUtils.isNotBlank(ingredient)){
            //将传进来的字符串成分转成list
            List<String> ingredientsList = new ArrayList<>(Arrays.asList(ingredient.split(",")));
            //获取所有标签成分id 遍历
            Map<String, String> tagMaps = tagList();
            Iterator<Map.Entry<String, String>> iterator = tagMaps.entrySet().iterator();
            while (iterator.hasNext()){
                Map.Entry<String, String> next = iterator.next();
                String key = next.getKey();
                String value = next.getValue();
                List<String> tagList =  new ArrayList<>(Arrays.asList(value.split(",")));
                ingredientsList.retainAll(tagList);
                System.out.println(ingredientsList.size());
                if(ingredientsList.size() == 0){
                    sbTag.append("no "+key).append("@!@") ;
                }
                //用完之后要重新赋予传进来的字符串转成list
                ingredientsList = new ArrayList<>(Arrays.asList(ingredient.split(",")));
            }
        }
        String resultTag = sbTag.toString();
        if(resultTag.contains("@!@")){
            resultTag = sbTag.substring(0, sbTag.lastIndexOf("@!@"));
        }
        return resultTag;
    }


    private  Map<String,String> tagList(){
        Map<String,String> tagMap = new HashMap<>();
        tagMap.put("fragrance","7,93,401,532,653,860,990,1059,1135,1268,1475,1762,1916,1957,1994,2039,2138,2497,2656,2703,3068,3070,3220,3259,3628,3646,3828,4239,4262,4306,5061,5294,5309,5483,5488,5489,5490,5763,5784,5886,5985,6077,6156,6157,6243,6267,6284,6317,6739,6768,7217,7285,10089,10794,11152,11259,11573,17076,17409,18413,18821,19490,26742,579,2298,2822,5887,6745,24305,26265,3257,2712,");
        tagMap.put("paraben","6,11,25,29,46,301,827,25739,892,976,5275,5276");
        tagMap.put("colorant","10,20,30,36,45,91,154,169,190,242,249,267,281,304,305,450,475,576,606,618,641,663,742,743,744,808,830,885,931,970,1021,1248,1258,1259,1273,1308,1414,1430,1446,1447,1517,1612,1730,1984,1985,2092,2136,2152,2153,2217,2218,2375,2480,2794,2795,2796,2797,2798,2799,2800,2801,2802,2803,2804,2805,2806,2807,2808,2809,2812,3775,4887,5411,5992,7536,7537,7542,7543,7556,7557,7559,7561,7562,7563,7564,7567,7570,7571,7572,7579,11821,11848,12923,12950,19214,19219,19361,19728,20759,20761,20762,20763,20764,20765,20766,20767,20768,20769,20770,20771,20772,20773,20774,24483,24484,25932,27023,10685,19716,4101,4104,4106,4107,4109,4218,4219,8677,9116,9530,10683,10687,10688,10690,10691,10696,12155,12164,17261,21949,528,70,131,157,187,189,668,956,1008,1112,1325,1338,1393,1445,1645,1766,1929,1930,2031,2032,2301,2374,2610,2783,2784,2786,2787,2788,2789,2790,2791,2792,7494,7495,7496,7498,7500,7515,7523,7534,12771,12835,17627,19804,19809,20756,20757,20758,1080,1811,2302,2472,2785,2793,3450,4095,4098,4099,4100,4217,4377,4378,4746,4862,6506,7688,7689,8674,10572,10648,10676,10677,10678,10679,10680,10681,10792,11431,11719,11727,11732,11925,12148,12152,12165,12228,13361,17037,17038,17047,17262,17559,18189,19445,19734,20310,20760,21145,21146,21147,21148,21573,21575,21576,21577,21578,21579,21665,21666,21667,21668,21669,21670,21671,21672,21673,21674,21675,21676,22188,22190,22216,22217,22218,22219,22220,22221,22222,22223,22224,22225,22226,22227,22228,22229,22230,22231,22232,22233,22234,22235,22236,22237,22238,22239,22240,22241,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,22252,22253,22817,22818,22819,23321,23322,23469,23697,23698,23699,24487,24488,24492,24493,24495,24496,24499,24500,24502,24503,24504,24511,25299,25300,25915,25916,25917,25920,25921,25923,25924,25925,25926,25927,25928,25929,25931,25933,25934,25935,26580,26644,27386,5378,19718,17517,19705,19720,19723,19727,5952,19702,19707,19708,11715,11730,17036,17039,18399,19710,19711,19714,19732,4379,4380,4382,4383,4384,7622,20022,20023,20160,20161,20162,20163,20164,20165,20166,20167,20168,20169,20170,20171,20172,20173,20174,20175,20176,20177,20181,20182,20184,20185,20186,20349,20754,37,1642,2690,2696,2813,2837,2839,2844,3045,6590,7493,7497,7503,7507,7513,7516,7517,7520,7530,7533,7535,7538,7544,7545,7546,7553,7555,7558,7560,7565,7573,7574,7575,7576,7577,7578,7580,7582,7585,7586,7597,7601,7616,7621,8288,8289,8410,12756,17629,17630,17633,17639,17641,17644,17647,17649,18611,18995,19262,19805,19806,19807,19808,20179,20180,20340,27017,27021,27025,28385,28387,28397,28398,28401,28405,28406,28409,28410,28412,28414,28415,28416,29636,29791,29795,31140,40969,40970,40971,40972,40973,40974,40975,40976,40977,40978,40979,40980,40981,40982,40983,40984,42233,42234,42235,43844,43845,45157,45158,10004506,10004507,10004562,10004778,10004779,10004780,10004904,10005211,10323428,10323614");
        tagMap.put("phenoxyethanol","3");
        tagMap.put("phthalates","10005107,11686,362,21275,21331,20389");
        tagMap.put("preservatives","3,28,32,53,56,93,98,118,125,152,155,158,166,191,248,264,271,300,346,421,428,432,697,734,804,873,912,982,989,1178,1183,1208,1222,1467,1477,1499,1696,1769,1939,2133,2202,2303,2339,2432,2585,2711,2718,3049,3257,3259,3260,3262,3273,3290,3291,4308,4360,4362,4884,4885,5564,5643,5739,5788,5888,6435,7665,8103,8104,9145,9958,11218,17722,19141,19230,19945,19974,20204,20222,20465,20473,21510,21838,22284,22308,23097,23154,23157,23158,23160,24423,24903,24905,24913,25826,25891,26249,26252,26316,32372,1158,10323497,10323651,6,11,25,29,46,301,827,25739,892,976,5275,5276,12740,2418,4342,6182");
        tagMap.put("alcohol","16,52,678,924,1104,3051,3052,3053,6026,17135,25507,25508,25509,25510,25511,25512,25513,25514,25515,25516,25517,25518,25519,25520,25521,25522,25523,25524,25525,25526,43807,43808,43809,43810,43811,43812,43813,43814,43815,43816,43817,43818,43819,43820,43822,43823,43824,43825,43826,43827,43828,43829,43830,43831,10000050");
        tagMap.put("mineralOil","111,124,126,184,240,73,31114");
        tagMap.put("sulfates","8613,299,2842,1493,2701,21334,1036,807,883,1470,1774,1940,2110,2349,2693,2840,2846,2926,3046,3048,3113,3791,4651,5305,5660,5716,5734,6487,6631,6799,6886,6889,7115,7421,7761,8261,8262");
        tagMap.put("formaldehyde","4360,5788,191,264,1158,2206,734");
        tagMap.put("dioxan","44669,24332,2718,10003318,10002662,10002364,10001992,10001976,10000155,10000129");
        tagMap.put("essentialOil","10323740,10323739,10323705,10323704,10005047,29914,27444,19396,18753,17894,17548,17321,17263,17236,17208,17191,17189,17173,17073,11669,11283,11278,10641,9514,17543,17479,17355,17342,17234,11482,11385,11237,11195,10204,10095,10073,9854,9514,8771,8738,3223,3953,8277,5916");
        tagMap.put("comedogenic","23,26,33,34,41,49,71,72,78,89,106,120,124,131,132,137,141,142,144,147,157,163,177,182,187,195,215,217,225,238,268,277,302,303,306,307,321,331,343,344,357,366,369,371,374,391,397,398,406,414,438,450,484,496,502,522,528,543,553,556,566,571,572,588,601,613,622,628,631,640,656,659,662,681,687,690,699,705,707,712,713,717,718,721,725,758,769,771,780,782,789,798,801,802,804,823,848,867,887,898,909,916,932,938,939,983,988,999,1009,1027,1031,1032,1037,1041,1050,1056,1069,1104,1106,1111,1123,1128,1132,1133,1140,1143,1167,1192,1209,1211,1221,1224,1226,1241,1260,1275,1281,1289,1290,1299,1300,1315,1335,1340,1358,1365,1386,1394,1415,1450,1451,1455,1469,1483,1492,1520,1528,1534,1546,1548,1563,1586,1588,1596,1599,1609,1613,1615,1620,1625,1648,1675,1680,1694,1695,1704,1732,1739,1742,1760,1767,1782,1783,1785,1805,1812,1814,1822,1828,1855,1857,1860,1868,1890,1892,1896,1909,1910,1911,1923,1934,1935,1966,1977,1980,1988,1997,2033,2041,2045,2094,2096,2133,2143,2147,2151,2155,2186,2213,2224,2232,2248,2249,2252,2256,2293,2308,2314,2319,2320,2361,2362,2376,2379,2392,2398,2400,2403,2404,2408,2409,2410,2439,2474,2512,2521,2523,2527,2553,2554,2558,2560,2597,2609,2612,2617,2621,2652,2667,2677,2873,2877,2879,2880,2881,2884,2885,2892,2899,2900,2903,2904,2905,2906,2908,2910,2911,2912,2915,2919,2928,2930,2935,2938,2939,2942,2943,2946,2949,2950,2951,2957,2961,2962,2969,2976,2982,2984,2988,2998,3014,3025,3027,3033,3305,3307,3308,3309,3629,3630,3736,3751,3752,3753,3902,3914,3915,3916,3944,4094,4098,4099,4100,4101,4104,4106,4107,4183,4263,4324,4350,4352,4445,4447,4448,4449,4450,4452,4469,4529,4531,4534,4537,4538,4539,4541,4542,4544,4547,4554,4556,4557,4563,4564,4566,5287,5295,5296,5297,5298,5328,5329,5336,5461,5462,5465,5466,5467,5468,5469,5546,5590,5636,5637,5638,5641,5642,5644,5646,5655,5661,5761,5799,5803,5888,5889,6535,6536,6537,6538,6539,6540,6541,6542,6543,6665,6773,6775,6796,6801,6891,6893,6939,7029,7030,7031,7032,7033,7034,7035,7036,7037,7038,7039,7040,7041,7042,7043,7044,7046,7047,7048,7063,7148,7179,7266,7820,7843,7844,8734,9611,10524,10534,10535,10679,10680,10681,10683,10690,10691,10696,10701,10994,11717,11718,11721,13252,14229,14230,14231,14233,14235,14236,17138,17332,17874,18539,19494,20465,23157,23392,27023,27364,28852,41330,22657");
        tagMap.put("EDTA","287,274,66,13");
        tagMap.put("SLS","163");
        tagMap.put("soap","559,779,829,865,955,996,1005,1019,1046,1120,1307,1324,1345,1468,1500,1505,1516,1809,2000,2142,2264,2454,2572,3282,4278,5658,5659,5739,6482,6483,7003,7270,15423,17248,17320,17448,17524,18069,5026");
        tagMap.put("FluorescentWhiteningAgent ","2058,44552,43314,43313,43312,29250,21990,21989,4438,3718,1577,13194");
        tagMap.put("heavy metal","20744,17363,618,29595,1334");
        tagMap.put("hormone","17277,17278,19607,21818,2176,6094");
        tagMap.put("antibiotic","20867,17510,20259");
        System.out.println(tagMap.size());
        return  tagMap;
    }
}
